home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
data
/
awkscrpt
/
strlib.awk
< prev
next >
Wrap
Text File
|
1995-02-11
|
9KB
|
427 lines
# 文字列操作関数ライブラリ
# sed の y///、perl の tr/// もどき関数
function tr(s,t,v ,i,l) {
s=exhyp(s)
t=exhyp(t)
l=jlength(s)
for(i=1; i<=l; i++) {
gsub(jsubstr(s,i,1),jsubstr(t,i,1),v)
}
return v
}
# 上の tr() より下の y() が2~6倍高速
function y(s,t,v ,ss,c) {
ss=exhyp(s)
t=exhyp(t)
s="[" s "]"
while( match(v,s) ) {
c=substr(v,RSTART,RLENGTH)
gsub(c, jsubstr(t,jindex(ss,c),1), v)
}
return v
}
function exhyp(v) {
if( !index(v,"-") ) return v
sub(/0-9/,"0123456789",v)
sub(/A-Z/,"ABCDEFGHIJKLMNOPQRSTUVWXYZ",v)
sub(/a-z/,"abcdefghijklmnopqrstuvwxyz",v)
sub(/0-9/,"0123456789",v)
sub(/a-z/,"abcdefghijklmnopqrstuvwxyz",v)
sub(/A-Z/,"ABCDEFGHIJKLMNOPQRSTUVWXYZ",v)
sub(/ぁ-ん/,"ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをん",v)
sub(/ァ-ン/,"ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲン",v)
return v
}
# 全角文字→半角文字変換
#function tohan(s) {
# s=y("0-9A-Za-z","0-9A-Za-z",s)
# return s
#}
# 上のよりも下の関数の方が速い場合がある。
function tohan(s) {
gsub(/0/,"0",s)
gsub(/1/,"1",s)
gsub(/2/,"2",s)
gsub(/3/,"3",s)
gsub(/4/,"4",s)
gsub(/5/,"5",s)
gsub(/6/,"6",s)
gsub(/7/,"7",s)
gsub(/8/,"8",s)
gsub(/9/,"9",s)
gsub(/A/,"A",s)
gsub(/B/,"B",s)
gsub(/C/,"C",s)
gsub(/D/,"D",s)
gsub(/E/,"E",s)
gsub(/F/,"F",s)
gsub(/G/,"G",s)
gsub(/H/,"H",s)
gsub(/I/,"I",s)
gsub(/J/,"J",s)
gsub(/K/,"K",s)
gsub(/L/,"L",s)
gsub(/M/,"M",s)
gsub(/N/,"N",s)
gsub(/O/,"O",s)
gsub(/P/,"P",s)
gsub(/Q/,"Q",s)
gsub(/R/,"R",s)
gsub(/S/,"S",s)
gsub(/T/,"T",s)
gsub(/U/,"U",s)
gsub(/V/,"V",s)
gsub(/W/,"W",s)
gsub(/X/,"X",s)
gsub(/Y/,"Y",s)
gsub(/Z/,"Z",s)
gsub(/a/,"a",s)
gsub(/b/,"b",s)
gsub(/c/,"c",s)
gsub(/d/,"d",s)
gsub(/e/,"e",s)
gsub(/f/,"f",s)
gsub(/g/,"g",s)
gsub(/h/,"h",s)
gsub(/i/,"i",s)
gsub(/j/,"j",s)
gsub(/k/,"k",s)
gsub(/l/,"l",s)
gsub(/m/,"m",s)
gsub(/n/,"n",s)
gsub(/o/,"o",s)
gsub(/p/,"p",s)
gsub(/q/,"q",s)
gsub(/r/,"r",s)
gsub(/s/,"s",s)
gsub(/t/,"t",s)
gsub(/u/,"u",s)
gsub(/v/,"v",s)
gsub(/w/,"w",s)
gsub(/x/,"x",s)
gsub(/y/,"y",s)
gsub(/z/,"z",s)
return s
}
# 半角文字→全角文字変換
#function tozen(s) {
# s=y("0-9A-Za-z","0-9A-Za-z",s)
# return s
#}
# 上のよりも下の関数の方が速い場合がある。
function tozen(s) {
gsub(/0/,"0",s)
gsub(/1/,"1",s)
gsub(/2/,"2",s)
gsub(/3/,"3",s)
gsub(/4/,"4",s)
gsub(/5/,"5",s)
gsub(/6/,"6",s)
gsub(/7/,"7",s)
gsub(/8/,"8",s)
gsub(/9/,"9",s)
gsub(/A/,"A",s)
gsub(/B/,"B",s)
gsub(/C/,"C",s)
gsub(/D/,"D",s)
gsub(/E/,"E",s)
gsub(/F/,"F",s)
gsub(/G/,"G",s)
gsub(/H/,"H",s)
gsub(/I/,"I",s)
gsub(/J/,"J",s)
gsub(/K/,"K",s)
gsub(/L/,"L",s)
gsub(/M/,"M",s)
gsub(/N/,"N",s)
gsub(/O/,"O",s)
gsub(/P/,"P",s)
gsub(/Q/,"Q",s)
gsub(/R/,"R",s)
gsub(/S/,"S",s)
gsub(/T/,"T",s)
gsub(/U/,"U",s)
gsub(/V/,"V",s)
gsub(/W/,"W",s)
gsub(/X/,"X",s)
gsub(/Y/,"Y",s)
gsub(/Z/,"Z",s)
gsub(/a/,"a",s)
gsub(/b/,"b",s)
gsub(/c/,"c",s)
gsub(/d/,"d",s)
gsub(/e/,"e",s)
gsub(/f/,"f",s)
gsub(/g/,"g",s)
gsub(/h/,"h",s)
gsub(/i/,"i",s)
gsub(/j/,"j",s)
gsub(/k/,"k",s)
gsub(/l/,"l",s)
gsub(/m/,"m",s)
gsub(/n/,"n",s)
gsub(/o/,"o",s)
gsub(/p/,"p",s)
gsub(/q/,"q",s)
gsub(/r/,"r",s)
gsub(/s/,"s",s)
gsub(/t/,"t",s)
gsub(/u/,"u",s)
gsub(/v/,"v",s)
gsub(/w/,"w",s)
gsub(/x/,"x",s)
gsub(/y/,"y",s)
gsub(/z/,"z",s)
return s
}
# ひらがな→カタカナ変換
#function tokata(s) {
# gsub(/う゛/,"ヴ",s)
# s=y("ぁ-ん","ァ-ン",s)
# return s
#}
function tokata(s) {
gsub(/う゛/,"ヴ",s)
gsub(/あ/,"ア",s)
gsub(/い/,"イ",s)
gsub(/う/,"ウ",s)
gsub(/え/,"エ",s)
gsub(/お/,"オ",s)
gsub(/か/,"カ",s)
gsub(/き/,"キ",s)
gsub(/く/,"ク",s)
gsub(/け/,"ケ",s)
gsub(/こ/,"コ",s)
gsub(/さ/,"サ",s)
gsub(/し/,"シ",s)
gsub(/す/,"ス",s)
gsub(/せ/,"セ",s)
gsub(/そ/,"ソ",s)
gsub(/た/,"タ",s)
gsub(/ち/,"チ",s)
gsub(/つ/,"ツ",s)
gsub(/て/,"テ",s)
gsub(/と/,"ト",s)
gsub(/な/,"ナ",s)
gsub(/に/,"ニ",s)
gsub(/ぬ/,"ヌ",s)
gsub(/ね/,"ネ",s)
gsub(/の/,"ノ",s)
gsub(/は/,"ハ",s)
gsub(/ひ/,"ヒ",s)
gsub(/ふ/,"フ",s)
gsub(/へ/,"ヘ",s)
gsub(/ほ/,"ホ",s)
gsub(/ま/,"マ",s)
gsub(/み/,"ミ",s)
gsub(/む/,"ム",s)
gsub(/め/,"メ",s)
gsub(/も/,"モ",s)
gsub(/や/,"ヤ",s)
gsub(/ゆ/,"ユ",s)
gsub(/よ/,"ヨ",s)
gsub(/ら/,"ラ",s)
gsub(/り/,"リ",s)
gsub(/る/,"ル",s)
gsub(/れ/,"レ",s)
gsub(/ろ/,"ロ",s)
gsub(/わ/,"ワ",s)
gsub(/を/,"ヲ",s)
gsub(/ん/,"ン",s)
gsub(/が/,"ガ",s)
gsub(/ぎ/,"ギ",s)
gsub(/ぐ/,"グ",s)
gsub(/げ/,"ゲ",s)
gsub(/ご/,"ゴ",s)
gsub(/ざ/,"ザ",s)
gsub(/じ/,"ジ",s)
gsub(/ず/,"ズ",s)
gsub(/ぜ/,"ゼ",s)
gsub(/ぞ/,"ゾ",s)
gsub(/だ/,"ダ",s)
gsub(/ぢ/,"ヂ",s)
gsub(/づ/,"ヅ",s)
gsub(/で/,"デ",s)
gsub(/ど/,"ド",s)
gsub(/ば/,"バ",s)
gsub(/び/,"ビ",s)
gsub(/ぶ/,"ブ",s)
gsub(/べ/,"ベ",s)
gsub(/ぼ/,"ボ",s)
gsub(/ぱ/,"パ",s)
gsub(/ぴ/,"ピ",s)
gsub(/ぷ/,"プ",s)
gsub(/ぺ/,"ペ",s)
gsub(/ぽ/,"ポ",s)
gsub(/ぁ/,"ァ",s)
gsub(/ぃ/,"ィ",s)
gsub(/ぅ/,"ゥ",s)
gsub(/ぇ/,"ェ",s)
gsub(/ぉ/,"ォ",s)
gsub(/っ/,"ッ",s)
gsub(/ゃ/,"ャ",s)
gsub(/ゅ/,"ュ",s)
gsub(/ょ/,"ョ",s)
gsub(/ゎ/,"ヮ",s)
return s
}
# カタカナ→ひらがな変換
#function tohira(s) {
# gsub(/ヴ/,"う゛",s)
# s=y("ァ-ン","ぁ-ん",s)
# return s
#}
function tohira(s) {
gsub(/ヴ/,"う゛",s)
gsub(/ア/,"あ",s)
gsub(/イ/,"い",s)
gsub(/ウ/,"う",s)
gsub(/エ/,"え",s)
gsub(/オ/,"お",s)
gsub(/カ/,"か",s)
gsub(/キ/,"き",s)
gsub(/ク/,"く",s)
gsub(/ケ/,"け",s)
gsub(/コ/,"こ",s)
gsub(/サ/,"さ",s)
gsub(/シ/,"し",s)
gsub(/ス/,"す",s)
gsub(/セ/,"せ",s)
gsub(/ソ/,"そ",s)
gsub(/タ/,"た",s)
gsub(/チ/,"ち",s)
gsub(/ツ/,"つ",s)
gsub(/テ/,"て",s)
gsub(/ト/,"と",s)
gsub(/ナ/,"な",s)
gsub(/ニ/,"に",s)
gsub(/ヌ/,"ぬ",s)
gsub(/ネ/,"ね",s)
gsub(/ノ/,"の",s)
gsub(/ハ/,"は",s)
gsub(/ヒ/,"ひ",s)
gsub(/フ/,"ふ",s)
gsub(/ヘ/,"へ",s)
gsub(/ホ/,"ほ",s)
gsub(/マ/,"ま",s)
gsub(/ミ/,"み",s)
gsub(/ム/,"む",s)
gsub(/メ/,"め",s)
gsub(/モ/,"も",s)
gsub(/ヤ/,"や",s)
gsub(/ユ/,"ゆ",s)
gsub(/ヨ/,"よ",s)
gsub(/ラ/,"ら",s)
gsub(/リ/,"り",s)
gsub(/ル/,"る",s)
gsub(/レ/,"れ",s)
gsub(/ロ/,"ろ",s)
gsub(/ワ/,"わ",s)
gsub(/ヲ/,"を",s)
gsub(/ン/,"ん",s)
gsub(/ガ/,"が",s)
gsub(/ギ/,"ぎ",s)
gsub(/グ/,"ぐ",s)
gsub(/ゲ/,"げ",s)
gsub(/ゴ/,"ご",s)
gsub(/ザ/,"ざ",s)
gsub(/ジ/,"じ",s)
gsub(/ズ/,"ず",s)
gsub(/ゼ/,"ぜ",s)
gsub(/ゾ/,"ぞ",s)
gsub(/ダ/,"だ",s)
gsub(/ヂ/,"ぢ",s)
gsub(/ヅ/,"づ",s)
gsub(/デ/,"で",s)
gsub(/ド/,"ど",s)
gsub(/バ/,"ば",s)
gsub(/ビ/,"び",s)
gsub(/ブ/,"ぶ",s)
gsub(/ベ/,"べ",s)
gsub(/ボ/,"ぼ",s)
gsub(/パ/,"ぱ",s)
gsub(/ピ/,"ぴ",s)
gsub(/プ/,"ぷ",s)
gsub(/ペ/,"ぺ",s)
gsub(/ポ/,"ぽ",s)
gsub(/ァ/,"ぁ",s)
gsub(/ィ/,"ぃ",s)
gsub(/ゥ/,"ぅ",s)
gsub(/ェ/,"ぇ",s)
gsub(/ォ/,"ぉ",s)
gsub(/ッ/,"っ",s)
gsub(/ャ/,"ゃ",s)
gsub(/ュ/,"ゅ",s)
gsub(/ョ/,"ょ",s)
gsub(/ヮ/,"ゎ",s)
return s
}
# /[ぁ-ん]-/の表現を/[ぁ-ん][あお]/に変換
function notyo(s) {
gsub(/[ぁ-ん]-/,"&ー",s)
gsub(/[あかさたなはまやらわがざだばぱぁゃゎ]-ー/,"&あ",s)
gsub(/[いきしちにひみりゐぎじぢびぴぃ]-ー/,"&い",s)
gsub(/[うくすつぬふむゆるぐずづぶぷぅゅ]-ー/,"&う",s)
gsub(/[えけせてねへめれゑげぜでべぺぇ]-ー/,"&え",s)
gsub(/[おこそとのほもよろをごぞどぼぽぉょ]-ー/,"&お",s)
gsub(/-ー/,"",s)
return s
}
# /[ぁ-ん]-/の表現を/[ぁ-ん][あお]/に変換
function notyo2(s) {
gsub(/[ぁ-ん]-/,"&ー",s)
gsub(/[あかさたなはまやらわがざだばぱぁゃゎ]-ー/,"&あ",s)
gsub(/[いきしちにひみりゐぎじぢびぴぃ]-ー/,"&い",s)
gsub(/[うくすつぬふむゆるぐずづぶぷぅゅ]-ー/,"&う",s)
gsub(/[えけせてねへめれゑげぜでべぺぇ]-ー/,"&い",s)
gsub(/[おこそとのほもよろをごぞどぼぽぉょ]-ー/,"&う",s)
gsub(/-ー/,"",s)
return s
}
# /[ぁ-ん][あお]/の表現を/[ぁ-ん]-/に変換
function tyo(s) {
gsub(/[あかさたなはまやらわがざだばぱぁゃゎ]あ/,"&ー",s)
gsub(/[えけせてねへめれゑげぜでべぺぇ]え/,"&ー",s)
gsub(/[えけせてねへめれゑげぜでべぺぇ]い/,"&ー",s)
gsub(/[いきしちにひみりゐぎじぢびぴぃ]い/,"&ー",s)
gsub(/[おこそとのほもよろをごぞどぼぽぉょ]お/,"&ー",s)
gsub(/[おこそとのほもよろをごぞどぼぽぉょ]う/,"&ー",s)
gsub(/[うくすつぬふむゆるぐずづぶぷぅゅ]う/,"&ー",s)
gsub(/[あいうえお]ー/,"-",s)
return s
}
# ひらがな小文字→ひらがな大文字
#function omoji(s) {
# s=y("ぁぃぅぇぉっゃゅょゎ","あいうえおつやゆよわ",s)
# return s
#}
function omoji(s) {
gsub(/ぁ/,"あ",s)
gsub(/ぃ/,"い",s)
gsub(/ぅ/,"う",s)
gsub(/ぇ/,"え",s)
gsub(/ぉ/,"お",s)
gsub(/っ/,"つ",s)
gsub(/ゃ/,"や",s)
gsub(/ゅ/,"ゆ",s)
gsub(/ょ/,"よ",s)
gsub(/ゎ/,"わ",s)
return s
}
# 任意の文字のn個の文字列を返す 入力 c:任意の文字, n:文字列の個数
function nstring(c,n ,s) {
s=sprintf("%" n "s","")
gsub(" ",c,s)
return s
}